//////////////////////////////////////////////////////////////////////////////////
//	Copyright 2011 by Yosef Grabivker, ryuho@homenetworksoft.com
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//////////////////////////////////////////////////////////////////////////////////

#ifndef __PROP_STOR_YG_H__
#define __PROP_STOR_YG_H__

#include "def.h"
#include "../common/MarkupSTL.h"
#include <map>

class CPropertyStorage: public IPropStorage
{
public:
							CPropertyStorage(class CConfigData& cfgStorage, class CGUILogic& logic);
							~CPropertyStorage(void);

	virtual bool			IsChanged(PANELTYPE pt, const PROPENTRY& pp);
	virtual void			GetProperty(PANELTYPE pt, PROPENTRY& pp);
	virtual void			SetProperty(PANELTYPE pt, const PROPENTRY& pp);
	
	void					LoadDefault();
	void					Load();
	void					Save();

	//Run at startup
	bool					GetBootRun();
	void					SetBootRun(bool bVal=true);

	//NAT Optimization
	bool					GetEnableNATOpt();
	void					SetEnableNATOpt(bool bVal=true);

	//NAT Size Optimization
	bool					GetEnableNATSizeOpt();
	void					SetEnableNATSizeOpt(bool bVal=true);

	//Peer To Peer
	bool					GetEnableP2PNetworkOpt();
	void					SetEnableP2PNetworkOpt(bool bVal=true);

	//WWW
	bool					GetEnableWWWOpt();
	void					SetEnableWWWOpt(bool bVal=true);


	//Language
	long					GetLanguage();
	void					SetLanguage(long val);

	//TCP
	bool					GetEnableTCPOpt();
	void					SetEnableTCPOpt(bool bVal=true);

	//icmp
	bool					GetEnableICMPOpt();
	void					SetEnableICMPOpt(bool bVal=true);

	//advanced
	bool					GetEnableAdvancedOpt();
	void					SetEnableAdvancedOpt(bool bVal=true);

	//advanced opt list
	STRINGPAIRLIST			GetAdvancedOptList();

	void					SetAdvancedOptListProperty(const wxString& strProp, const wxString& strVal);

	void					SetAdvancedOptList(const STRINGPAIRLIST& val);

	//Start up script
	void					SetEnableStartUpScript( bool bSet );
	bool					GetEnableStartUpScript();

	void					SetStartUpScriptFileName( const wxString& str );
	wxString				GetStartUpScriptFileName();

	//Proc Kill
	void					SetEnableProcKill( bool bSet );
	bool					GetEnableProcKill();

	TEXTLIST				GetProcKillList();
	void					SetProcKillList(const TEXTLIST& val);

	//Mod Unload
	void					SetEnableModUnload( bool bSet );
	bool					GetEnableModUnload();

	TEXTLIST				GetModUnloadList();
	void					SetModUnloadList(const TEXTLIST& val);



	//Syslog from router only
	bool					GetSysLogFromRouterOnly();
	void					SetSysLogFromRouterOnly(bool bVal=true);

	//Syslog log blocked MACs
	bool					GetLogBlockedMAC();
	void					SetLogBlockedMAC(bool bVal=true);

	//Syslog enable auto log save
	void					SetEnableSyslogSave( bool bSet );
	bool					GetEnableSyslogSave();

	//Syslog log file name
	void					SetSyslogSaveFileName( const wxString& str );
	wxString				GetSyslogSaveFileName();

	//Syslog log file limit
	void					SetSyslogSaveLimit( long lLimit );
	long					GetSyslogSaveLimit();

	void					SetSysLogUDPPort(long lLimit);
	long					GetSysLogUDPPort();

	//Syslog autoconfig
	void					SetEnableSyslogAutoConfig( bool bSet );
	bool					GetEnableSyslogAutoConfig();
	void					SetSyslogAutoConfigLevel(long lLimit);
	long					GetSyslogAutoConfigLevel();


	//Syslog actions
	SYSLOGACTIONS			GetSysLogActions();
	void					SetSysLogActions(const SYSLOGACTIONS& act);

	//Search filter
	void					SetSearchFilters(cSearchOwnerID cID, const FILTERS& filters);
	FILTERS					GetSearchFilters(cSearchOwnerID cID );

	//MAC list
	void					SetMACList(const MACBLOCK& lstMAC);
	MACBLOCK				GetMACList(cMACBlockRuleId cID);

	//Colors
	void					SetRecvColor( const wxColor& clr );
	wxColor					GetRecvColor();
	void					SetTransmColor( const wxColor& clr );
	wxColor					GetTransmColor();

	//SMTP Server
	wxString				GetSMTPServer();
	void					SetSMTPServer(const wxString& str);

	//SMTP Server Port
	unsigned short			GetSMTPServerPort();
	void					SetSMTPServerPort(unsigned short wPort);

	//SMTP User
	wxString				GetSMTPUser();
	void					SetSMTPUser(const wxString& str);

	//SMTP Passw
	wxString				GetSMTPPassw();
	void					SetSMTPPassw(const wxString& str);

	//SMTP From
	wxString				GetSMTPFrom();
	void					SetSMTPFrom(const wxString& str);

	//SMTP To
	wxString				GetSMTPTo();
	void					SetSMTPTo(const wxString& str);

	//Send application Log
	bool					GetSendAppLog();
	void					SetSendAppLog(bool bVal=true);

	//Send syslog Log
	bool					GetSendSysLog();
	void					SetSendSysLog(bool bVal=true);

	//Syslog email send level
	long					GetSyslogSendLevel();
	void					SetSyslogSendLevel(long lLevel);

	//Send interval
	time_t					GetSendPeriod();
	void					SetSendPeriod(time_t t);

	//GUI: Show help panel
	bool					GetShowHelpPanel();
	void					SetShowHelpPanel(bool bVal=true);

	//GUI: Update speed
	time_t					GetUpdateSpeed();
	void					SetUpdateSpeed(time_t t);

	//Port forwarding
	bool					GetAutoPortForward();
	void					SetAutoPortForward(bool bVal=true);

	unsigned short			GetAutoPortForwardLowPort();
	void					SetAutoPortForwardLowPort(unsigned short val);

	PORTFORWARDLIST			GetPortForwardLst();
	void					SetPortForwardLst(const PORTFORWARDLIST& lst);

	//Update check
	bool					GetUpdCheck();
	void					SetUpdCheck(bool bCheck=true);

	//Reboot scheduler
	std::string				GetScheduler();
	void					SetScheduler(const std::string& str );
	bool					GetSchedulerEnabled();
	void					SetSchedulerEnabled(bool bSet);

	//Log
	void					SetEnableAppLogSave( bool bSet );
	bool					GetEnableAppLogSave();

	void					SetAppLogSaveFileName( const wxString& str );
	wxString				GetAppLogSaveFileName();

	void					SetAppLogSaveLimit( long lLimit );
	long					GetAppLogSaveLimit();

	void					SetAppLogStatusInterval( long lLimit );
	long					GetAppLogStatusInterval();

	void					SetEnablePerfomanceLog( bool bSet );
	bool					GetEnablePerfomanceLog();

	void					SetEnableConnectionsLog( bool bSet );
	bool					GetEnableConnectionsLog();

	void					SetEnableBandwidthLog( bool bSet );
	bool					GetEnableBandwidthLog();

	void					SetEnableAccessLog( bool bSet );
	bool					GetEnableAccessLog();

	void					SetEnableADSLLog( bool bSet );
	bool					GetEnableADSLLog();

	void					SetEnableWirelessLog( bool bSet );
	bool					GetEnableWirelessLog();

	void					SetEnablePingLog( bool bSet );
	bool					GetEnablePingLog();


	void					SetEnableAllowPFPolicy(bool bSet);
	bool					GetEnableAllowPFPolicy();

	void					SetAllowPFPolicy(const TEXTLIST& lst );
	TEXTLIST				GetAllowPFPolicy();

	void					SetEnableBlockPFPolicy(bool bSet);
	bool					GetEnableBlockPFPolicy();

	void					SetBlockPFPolicy(const TEXTLIST& lst );
	TEXTLIST				GetBlockPFPolicy();

	void					SavePingList(const PINGDATALIST& lst);
	PINGDATALIST			LoadPingList();

protected:
	void					SaveProperty(PANELTYPE pt, const PROPENTRY& pp);
	bool					GetBoolProperty(const char* szProp, bool bDef=false);
	void					SetBoolProperty(const char* szProp, bool bVal);
	wxString				GetStringProperty(const char* szProp);
	std::string				GetStringPropertyAscii(const char* szProp);

	void					SetStringProperty(const char* szProp, const wxString& strVal);
	void					SetStringPropertyAscii(const char* szProp, const std::string& strVal);

	long					GetLongProperty(const char* szProp, long def=0);
	void					SetLongProperty(const char* szProp, long lVal);
	TEXTLIST				GetStringList(const char* szListID);
	void					SetStringList(const char* szListID, const TEXTLIST& lst );

	
private:	
	class CConfigData&		m_cfgStorage;
	typedef std::map<PANELTYPE, PROPENTRY> PROPS;
	PROPS					m_props;
	SYSLOGACTIONS			m_syslogactions;
	CMarkupSTL				m_doc;
	class CGUILogic&		m_logic;
};

#endif //__PROP_STOR_YG_H__